define(['app'], function(app) {
	'use strict';

	// 实例化方法
	var factory = function(Http) {

		  function get_data_getlist(result){
            if(HTTP_ISLOGIC){
                result='{"success":true,"msg":"","result":{"act_id":"001","name":"团购","start_time":"2017/01/01 09:00:00","apply_end_time":"2017/01/01 09:00:00","end_time":"2017/01/31 09:00:00","create_group":true,"has_packets":true,"brand_id":"001","cat_type_id":"001","goods_id":"001","goods_name":"一字螺丝刀","image":"img/upload/pro-img01.jpg","price":5,"count":100,"word_id":"001","word":""},"session":"7311da98bd0f18eb15a96bcb263f4153"}';
                return JSON.parse(result);
            }else{
                   return result;
            }
        }
		  //商品检索
        function get_data_goods_list(result) {
            if(HTTP_ISLOGIC) {
                result = '{"success":true,"msg":"","result":{"store_count":"500","goods":[{"goods_id":"001","name":"十字螺丝刀","introduce":"十字螺丝刀","price":10.5,"mktprice":11,"preprice":10,"store_id":"WuJin_1","store_name":"五金一店","image":{"id":1,"image":"img/upload/pro-img01.jpg"},"store":1234,"cat_type_name":"工具-小型工具-螺丝刀"},{"goods_id":"002","name":"一字螺丝刀","introduce":"一字螺丝刀","price":10.5,"mktprice":11,"preprice":10,"store_id":"WuJin_1","store_name":"五金一店","image":{"id":2,"image":"img/upload/pro-img01.jpg"},"store":1000,"cat_type_name":"工具-小型工具-螺丝刀"},{"goods_id":"003","name":"扳手","introduce":"好扳手","price":5.5,"mktprice":8,"preprice":5,"store_id":"WuJin_1","store_name":"五金一店","image":{"id":2,"image":"img/upload/pro-img01.jpg"},"store":1000,"cat_type_name":"工具-小型工具-螺丝刀"},{"goods_id":"004","name":"活动扳手","introduce":"好活动扳手","price":5.5,"mktprice":8,"preprice":5,"store_id":"WuJin_1","store_name":"五金一店","image":{"id":2,"image":"img/upload/pro-img01.jpg"},"store":1000,"cat_type_name":"工具-小型工具-螺丝刀"}],"page":[{"limit":8,"tPage":5,"cPage":1,"count":4}]},"session":"7311da98bd0f18eb15a96bcb263f4153"}';
                return JSON.parse(result);
            } else
                return result
        }

		// 返回信息
		return {
			  //获取对应的新品测试信息
		    getlist: function(act_id,callback){
		        Http.post({
		            method:'marketing.goodstest.detail',
		            session:'',
		            act_id:act_id
		        },
                    function(result) {
                        //请求成功
                        if(callback)
                            callback(get_data_getlist(result).result);
                    },
                    function(e) {
                        //请求异常
                    },
                    function() {
                        //请求完成，一般不做什么事情
                    }
               );

		    },
			//编辑
			get_addtest : function( act_id,
					  name,
					  start_time,
					  end_time,
					  create_group,
					  has_packets,
					  brand_id,
					  cat_type_id,
					  goods_id,
					  price,
					  count,callback) {
				Http.post({
					method : 'marketing.goodstest.createedit',
					session:"",
					  act_id:act_id,
					  name:name,
					  start_time:start_time,
					  end_time:end_time,
					  create_group:create_group,
					  has_packets:has_packets,
					  brand_id:brand_id,
					  cat_type_id:cat_type_id,
					  goods_id:goods_id,
					  price:price,
					  count:count
				}, function(result) {
					// 请求成功
					if (callback)
						callback(result);
				}, function(e) {
					// 请求异常
				}, function() {
					// 请求完成，一般不做什么事情
				});
			},
			//检索商品获取
            goods_list: function(cat_type, name, brand_id, callback) {
                Http.post({
                    method: 'goods.common.getlist',
                    cat_type: cat_type,
                    paglimit: 8,
                    nPage: 1,
                    show_count: 5,
                    brand_id: brand_id,
                    picSize: 'CS',
                    name: name
                }, function(result) {
                    if(callback)
                        callback(get_data_goods_list(result).result);
                }, function(e) {

                }, function() {

                })
            },

		};
	}

	factory.$inject = [ 'Http' ];
	return app.registerService("Addtest", factory);
});